package com.learn.thread;

import cn.hutool.http.HttpUtil;

import java.io.File;

public class TestThread4 implements Runnable {
    private String url;
    private String targetName;

    public TestThread4(String url, String targetName) {
        this.url = url;
        this.targetName = targetName;
    }

    @Override
    public void run() {
        WebLoaderResource2 webloaderResource2 = new WebLoaderResource2();
        webloaderResource2.downloadImage(url, targetName);
        System.out.println("当前下载的文件名称为" + targetName);
    }

    public static void main(String[] args) {
        TestThread4 t4 = new TestThread4("https://oss.javaguide.cn/github/javaguide/books/image-20220424103035793.png", "t4.png");
        TestThread4 t5 = new TestThread4("https://oss.javaguide.cn/github/javaguide/books/image-20220424101217849.png", "t5.png");
        TestThread4 t6 = new TestThread4("https://oss.javaguide.cn/github/javaguide/books/image-20220424103124893.png", "t6.png");
        new Thread(t4).start();
        new Thread(t5).start();
        new Thread(t6).start();
    }
}

class WebLoaderResource2 {
    public void downloadImage(String url, String targetName) {
        HttpUtil.downloadFile(url, new File(targetName));
    }
}
